import type { Recordable } from '@vben/types';

import { requestClient } from '#/api/request';

export namespace SystemRoleApi {
  export interface SystemRole {
    [key: string]: any;
    id: string;
    name: string;
    code: string;
    permissions: string[];
    remark?: string;
    status: string;
    sex: number;
    createTime: number;
  }
}

/**
 * 获取角色列表数据
 */
async function getRoleList(
  pageNum: number,
  pageSize: number,
  filterData: Recordable<any>,
) {
  return requestClient.post<Array<SystemRoleApi.SystemRole>>(
    '/role/queryRolePage',
    {
      pageNum,
      pageSize,
      filterData,
    },
  );
}

/**
 * 创建角色
 * @param data 角色数据
 */
async function createRole(data: Omit<SystemRoleApi.SystemRole, 'id'>) {
  return requestClient.post('/role/addRole', data);
}

/**
 * 更新角色
 *
 * @param id 角色 ID
 * @param data 角色数据
 */
async function updateRole(
  id: string,
  data: Omit<SystemRoleApi.SystemRole, 'id'>,
) {
  // 设置主键id
  data.id = id;
  return requestClient.post(`/role/editRole`, data);
}

/**
 * 删除角色
 * @param id 角色 ID
 */
async function deleteRole(id: string) {
  return requestClient.post(`/role/deleteRole?id=${id}`);
}

/**
 * 启用/禁用角色
 */
async function enableRole(id: string, status: number) {
  return requestClient.post(`/role/enableRole?id=${id}&status=${status}`);
}

export { createRole, deleteRole, enableRole, getRoleList, updateRole };
